﻿

using CodeCamp.BL.Model;

namespace CodeCamp.BL.Helpers
{
	public static class HtmlExtensions
	{

		public static string ShowImage(this Attachment attachment, string controller, string action, int height, int width, string noImagePath)
		{
			string heightAttribute = height > 0 ? "height='" + height + "'" : string.Empty;
			string widthAttribute = width > 0 ? "width='" + height + "'" : string.Empty;
			if (attachment == null)
			{
				return string.Format("<img src='{0}' alt='{1}' {2} {3} />", noImagePath, noImagePath, heightAttribute, widthAttribute);
			}

			return string.Format("<img src='/{0}/{1}/{2}' alt='{3}' {4} {5} />", controller, action, attachment.AttachmentID, attachment.Name, heightAttribute, widthAttribute);
		}

		public static string ShowImage(this Attachment attachment, string controller, string action, int height, int width)
		{
			return ShowImage(attachment, controller, action, int.MinValue, int.MinValue, string.Empty);
		}

		public static string ShowImage(this Attachment attachment, string controller, string action)
		{
			return ShowImage(attachment, controller, action, int.MinValue, int.MinValue);
		}

		public static string ShowDownloadLink(this Attachment attachment, string controller, string action)
		{
			if (attachment == null)
			{
				return "<!-- no attachment -->";
			}

			return string.Format("<a href='/{0}/{1}/{2}'>{3}</a>", controller, action, attachment.AttachmentID, attachment.Name);
		}
	}
}
